package com.example.sulei.rootchangerinfo.hook;

import android.net.wifi.WifiInfo;
import android.telephony.TelephonyManager;
import android.util.Log;

import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XSharedPreferences;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

/**
 * Created by hp on 2017/4/16.
 */

public  abstract class BaseHook implements IXposedHookLoadPackage {

    /**
     * 通过反射调用方法
     */
    protected void hookMethod(final Class cl, final String method, final String result) {
        {
            try {
                // 类名+loadPackageParam.classLoader（照写）+方法名+参数类型（根据所hook方法的参数的类型，
                // 即有多少个写多少个，加上.class）+XC_MethodHook回调接口；
                XposedHelpers.findAndHookMethod(cl, method, new Object[]{new XC_MethodHook() {
                    @Override
                    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                        super.beforeHookedMethod(param);

                        XposedBridge.log("修改的内容：" + param.getResult().toString());
                    }

                    protected void afterHookedMethod(MethodHookParam param)
                            throws Throwable {
                        param.setResult(result);
                        Log.d("zz", param.getResult().toString());
                    }

                }});
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    }
}
